/*
 * COPYRIGHT. ShenZhen JiMi Technology Co., Ltd. 2017.
 * ALL RIGHTS RESERVED.
 *
 * No part of this publication may be reproduced, stored in a retrieval system, or transmitted,
 * on any form or by any means, electronic, mechanical, photocopying, recording, 
 * or otherwise, without the prior written permission of ShenZhen JiMi Network Technology Co., Ltd.
 *
 * Amendment History:
 * 
 * Date                   By              Description
 * -------------------    -----------     -------------------------------------------
 * 2017年12月19日    LongMin         Create the class
 * http://www.jimilab.com/
*/

package com.futuremap.ws.util;

import java.beans.PropertyEditorSupport;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;

/**
 * @FileName DatePropertyEditor.java
 * @Description:
 *
 * @Date 2017年12月19日 下午2:30:31
 * @author LongMin
 * @version 1.0
 */
public class DatePropertyEditor extends PropertyEditorSupport {

	public static final DatePropertyEditor SINGLETON = new DatePropertyEditor();

	public void setAsText(String text) throws IllegalArgumentException {
		if (StringUtils.isEmpty(text)) {
			return;
		}
		try {
			Long value = Long.parseLong(text);
			super.setValue(new Date(value));
		} catch (Exception e) {
		}
	}

	public String getAsText() {
		Date value = (Date) getValue();
		return value == null ? null : String.valueOf(value.getTime());
	}
}
